package cn.baizhi.service.impl;

import cn.baizhi.entity.Clazz;
import cn.baizhi.entity.Tag;
import cn.baizhi.feign.TagClient;
import cn.baizhi.mapper.ClazzMapper;
import cn.baizhi.service.ClazzService;
import cn.baizhi.vo.ClazzDto;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author LZM
 * @since 2021-12-03
 */
@Service
public class ClazzServiceImpl extends ServiceImpl<ClazzMapper, Clazz> implements ClazzService {

    @Autowired
    private ClazzMapper clazzMapper;

    @Autowired
    private TagClient tagClient;

    public List<ClazzDto> queryAll(){
        List<Clazz> clazzs = clazzMapper.selectList(null);
        List<ClazzDto> list = new ArrayList<>();

        for (Clazz clazz : clazzs) {
            Tag tag = tagClient.selectOne(clazz.getTagId()).getBody();

            list.add(new ClazzDto(clazz.getId(),clazz.getName(),clazz.getPath(),tag));

        }

        return list;
    }


}
